<?php
namespace app\admin\controller;
use think\Config;
use think\Controller;
use think\Request;
use think\Model;
use think\Db;
class Gelincard extends Base{
	// 卡卷展示首页展示
    public function index(){
       // $file = Config::get('card');
        $map['u.del'] = 0;
        $map['u.stat'] = 1;
        $info = Db::name('users_card')->alias('uc')->join('users u','uc.userid=u.id')->where($map)->field('u.wechatname,uc.Id,uc.doctors,uc.status')->order('uc.Id desc')->paginate(10,true);
        //print_r($info);die;
        $page = $info->render();
        $this->assign('info', $info);
        $this->assign('page', $page);
        return $this->fetch();
       // return view('index',['file'=>$file]);
    }
    // 搜索该卡卷
    public function gelin_search(){
     	$param = request()->param();
     	if(request()->isPost()){
            $id   = $param['key'];
            $file_php = Config::get('card');
            if(isset($file_php[$id])){
                $file[] = $file_php[$id];
    
            }else{
            	$file  = '';
            }
     	}else{
     		$file = '';
     	}
     	return view('index',['file'=>$file]);
    }
    // 卡卷使用明细
    public function card_detail(){
    	// 卡卷ID
        $id = request()->param('id')?request()->param('id'):null;
       
        $file_php = Config::get('card');
        foreach($file_php as $k=>$v){
            if($id==$v['card_id']){
                $list['money'] = $v['Amount'];
                $list['title'] = $v['title'];
            }
        }
        
    	if($id && isset($file_php[$id])){
            $file['kj']  = $file_php[$id];
            $sql = Db::name('users_card')->where('cardid',$id)->select();
            $file['card']= $sql;
    	}else{
    		$this->error('卡卷不存在');
        }
        $this->assign('list',$list);
        return view('card_detail',['file'=>$file]);
    }
    // 删除操作
    public function del(){
    	$idall = request()->param();
    	if(isset($idall['ids']) && $idall['ids']){
            $delarr = $idall['ids'];
            $sql = Db::name('users_card')->where('id','in',$delarr)->delete();
            $this->success('记录删除成功');
    	}else{
    		$this->error('卡卷不存在');
    	}
    }
}